//
//  VisitorLoginView.swift
//  SinaWeiBo_18
//
//  Created by apple on 15/10/7.
//  Copyright © 2015年 apple. All rights reserved.
//

import UIKit

protocol VisitorLoginViewDelegate : NSObjectProtocol{
    
    func visitorWillRegister()
    
    func visitorWillLogin()

}

class VisitorLoginView: UIView {
    
    weak var visitorDelegate : VisitorLoginViewDelegate?

    @IBOutlet weak var smallIcon: UIImageView!

    @IBOutlet weak var iconView: UIImageView!
    
    @IBOutlet weak var tipLabel: UILabel!
    
    func setUIInfo(imageName name: String, tipText: String, isHome : Bool){
    
        iconView.image = UIImage(named: name)
        
        tipLabel.text = tipText
        
        smallIcon.hidden = !isHome
        
        if isHome {
        
            startAnimation()
        }
    
    }
    
    private func startAnimation(){
        
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        
        anim.repeatCount = MAXFLOAT
        
        anim.duration = 15
        
        anim.toValue = 2 * M_PI
        
        //处于非活跃状态时 移除动画
        anim.removedOnCompletion = false
        
        smallIcon.layer.addAnimation(anim, forKey: nil)
        
    }
    
    @IBAction func didClickRegisterButton(sender: AnyObject) {
        
        visitorDelegate?.visitorWillRegister()
    }

    @IBAction func didClickLoginButton(sender: AnyObject) {
        
        visitorDelegate?.visitorWillLogin()
    }
    
}
